#!/bin/bash
set -e

source $(dirname $0)/version

cd $(dirname $0)/..

function build-image() {
  IMAGE=${REPO}/${1}:${TAG}
  DOCKERFILE=package/Dockerfile${2}
  if [ -e ${DOCKERFILE}.${ARCH} ]; then
      DOCKERFILE=${DOCKERFILE}.${ARCH}
  fi

  docker build -f ${DOCKERFILE} -t ${IMAGE} --build-arg ARCH=${ARCH} .
  echo Built ${IMAGE}

  if [ "$PUSH" = "true" ]; then
      docker push ${IMAGE}
  fi
}

build-image fleet
build-image fleet-agent .agent

./scripts/package-helm
